from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy


class LimitUpCloseStrategy(BaseStrategy):
    """
    风险策略：判断某个股票是否在涨停时收盘，涨停价根据前收盘价计算。
    如果是涨停收盘，则给2分。
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析某个股票是否在涨停时收盘。
        涨停价格根据前收盘价计算（前收盘价 * 1.1）。
        """
        node_point = 0
        description = ""

        # 确保至少有1天的交易数据
        if len(trade_info_list) >= 1:
            # 获取当天的交易数据（假设是最后一天）
            today = trade_info_list[-1]

            # 根据前收盘价计算涨停价格
            limit_up_price = today.pre_close * 1.1

            # 判断是否涨停收盘
            if today.close == limit_up_price:
                node_point += 2  # 涨停收盘得分 +2
                description += (
                    f"Stock closed at the limit up price of {limit_up_price}. "
                )

        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            config=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> StrategyInfoMetadata:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="limit_up_close",
            strategy_name="涨停收盘",
            strategy_group=StrategyGroup.RISK,  # 风险型策略
            strategy_type=StrategyType.PRICE,  # 根据价格类型
            analysis_day=1,
            strategy_level=3,  # 涨停收盘通常视为较强的信号，设置策略等级为3
        )
